<!DOCTYPE html>
<html>

<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }
        
        .wrap {
            width: 500px;
            margin: 100px auto 0;
        }
        
        table {
            border-collapse: collapse;
            border-spacing: 0;
            border: 1px solid #c0c0c0;
            width: 500px;
        }
        
        th,
        td {
            border: 1px solid #d0d0d0;
            color: #404060;
            padding: 10px;
        }
        
        th {
            background-color: #09c;
            font: bold 16px "微软雅黑";
            color: #fff;
        }
        
        td {
            font: 14px "微软雅黑";
        }
        
        tbody tr {
            background-color: #f0f0f0;
        }
    </style>
</head>

<body>
    <div class="wrap">
        <table>
            <thead>
                <tr>
                    <th>序号</th>
                    <th>姓名</th>
                    <th>课程</th>
                    <th>成绩</th>
                </tr>
            </thead>
            <tbody id="j_tb">
                <tr>
                    <td>
                        1
                    </td>
                    <td>柳岩</td>
                    <td>语文</td>
                    <td>100</td>

                </tr>
                <tr>
                    <td>
                        2
                    </td>
                    <td>苍老师</td>
                    <td>日语</td>
                    <td>100</td>
                </tr>
                <tr>
                    <td>
                        3
                    </td>
                    <td>凤姐</td>
                    <td>营销学</td>
                    <td>100</td>
                </tr>
                <tr>
                    <td>
                        4
                    </td>
                    <td>张飞</td>
                    <td>数学</td>
                    <td>10</td>
                </tr>
                <tr>
                    <td>
                        5
                    </td>
                    <td>小沈阳</td>
                    <td>英语</td>
                    <td>100</td>
                </tr>
                <tr>
                    <td>
                        6
                    </td>
                    <td>马户</td>
                    <td>体育</td>
                    <td>100</td>
                </tr>
                <tr>
                    <td>
                        7
                    </td>
                    <td>打不死的小强</td>
                    <td>体育</td>
                    <td>100</td>
                </tr>
            </tbody>
        </table>
    </div>
    <script>
        // var tbody = document.getElementById("j_tb");
        function my$(id) {
            return document.getElementById(id);
        }

        var tbody = my$("j_tb");
        var trs = tbody.children;
        for (var i = 0; i < trs.length; i++) {
            var tr = trs[i];
            //隔行变色
            if (i % 2 == 0) {
                tr.style.backgroundColor = "#cccccc";
            }else{
                tr.style.backgroundColor = "#c0c0c0";
            }

            //鼠标放上高亮显示
            tr.onmouseover = overHandle;
            tr.onmouseout = outHandle;
        }


        var bg;//鼠标离开的时候，记录当前的颜色
        function overHandle() {
            //记录当前的颜色
            bg = this.style.backgroundColor;
            //改变背景颜色
            this.style.backgroundColor = "lightyellow";
        }

        function outHandle() {

            //还原以上的颜色
            this.style.backgroundColor = bg;
        }

    </script>
</body>

</html>